#!/usr/bin/env python

import numpy as np




def transition_matrix(generation_size, field_size):
	P = np.zeros((generation_size+1, generation_size+1))
	for i in range(generation_size):
		P[i,i] = 1./(field_size**(generation_size-i))
		P[i+1,i] = 1.-P[i,i]
	P[generation_size,generation_size] = 1./(field_size**(generation_size-generation_size)) # = 1
	return np.matrix(P)
	
	
if __name__=='__main__':
	
	g = 8
	q = 2
	
	s = np.matrix(np.zeros((g+1,1)))
	s[0,0] = 1.
	s2 = s
	P = transition_matrix(g,q)
	
	prop = P**8*s
	
#	print prop, sum(prop[:-1])
			
	prop_sum = 0
	for i in range(g,2*g):
		prop = P**i*s
		prop_sum += sum(prop[:-1])
		
	print prop_sum
	print P**8*s
	
#	print P,s
	
#	for i in range(1,g+4):
#		s = P*s
#		print 'Probability vector after',i,'transmissions:'
#		print s




	
	
